﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace sentence
{
    public partial class BUGReport : Form
    {
        public BUGReport()
        {
            InitializeComponent();
        }

        public BUGReport(string message)
        {
            InitializeComponent();
            ContentTextBox.Text = message;
        }

        private void SubmitButton_Click(object sender, EventArgs e)
        {
            ReportSend();
        }

        public void ReportSend()
        {
            string postString = "name=" + NameTextBox.Text + "&mail=" + MailTextBox.Text + "&content=" + ContentTextBox.Text;//这里即为传递的参数，可以用工具抓包分析，也可以自己分析，主要是form里面每一个name都要加进来  
            byte[] postData = Encoding.UTF8.GetBytes(postString);//编码，尤其是汉字，事先要看下抓取网页的编码方式  
            string url = "http://sentence.sinaapp.com/bugreport.php";//地址  
            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header，如果改为GET方式的话就去掉这句话即可  
            byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流  
            string srcString = Encoding.UTF8.GetString(responseData);//解码
            if (MessageBox.Show("发送成功") == DialogResult.OK)
            {
                this.Close();
            }
        }
    }
}
